// 解析IP地址
function resolveIP() {
    var url ="/dubbo/resolveIp";
    var zkAddress =$("#zkAddress").val();
    var interfaceName =$.trim($("#interfaceName").val());
    $.ajax({
        url:url,
        method:"get",
        data:{
            zkAddress:zkAddress,
            interfaceName:interfaceName
        },
        success:function (responseMessage) {
            if(responseMessage.success){
               var ipList =responseMessage.data;
               var str;
               ipList.forEach(function (v) {
                    str+=" <option value='"+v+"'>"+v+"</option>"
               })
                $("#ip").empty();
                $("#ip").append(str);
            }else {
                Ewin.alert(responseMessage.msg);
            }
        }
    })
};
// 解析方法
function resolveMethod() {
    var url ="/dubbo/resolveMethod";
    var ip =$("#ip").val();
    var interfaceName =$.trim($("#interfaceName").val());
    $.ajax({
        url:url,
        method:"get",
        data:{
            ip:ip,
            interfaceName:interfaceName
        },
        success:function (responseMessage) {
            if(responseMessage.success){
                //data 是一个map类型，里面有两个Key
                //第一个是 param , 第二个是methodList
                var data =responseMessage.data;
                var methodList =data.methodList;
                var str;
                methodList.forEach(function (v) {
                    str+="<option value='"+v+"'>"+v+"</option>"
                });
                $("#interfaceMethod").empty();
                $("#interfaceMethod").append(str);
                var param =data.param;
                if(""!=param &&   'undefined' !=typeof (param)) {
                    // var json = JSON.stringify(param)
                    // $("#param").val(json)
                    paramEditor.set(param)
                }
            }else {
                Ewin.alert(responseMessage.msg);
            }
        }
    })
};
/**
 * 解析dubbo方法入参为了接口管理使用
 * **/
function resolveMethodForInterfaceManager() {
    var url ="/dubbo/resolveMethod";
    var ip =$("#ip").val();
    var interfaceName =$.trim($("#interfaceName").val());
    $.ajax({
        url:url,
        method:"get",
        data:{
            ip:ip,
            interfaceName:interfaceName
        },
        success:function (responseMessage) {
            if(responseMessage.success){
                //data 是一个map类型，里面有两个Key
                //第一个是 param , 第二个是methodList
                var data =responseMessage.data;
                var methodList =data.methodList;
                var str;
                methodList.forEach(function (v) {
                    str+="<option value='"+v+"'>"+v+"</option>"
                });
                $("#interfaceMethod").empty();
                $("#interfaceMethod").append(str);
                var param =data.param;
                var json = JSON.stringify(param)
                $("#param").val(json);
            }else {
                Ewin.alert(responseMessage.msg);
            }
        }
    })
};
function switchParamTemplate() {
    var url ="/dubbo/methodParamTemplates";
    var ip =$("#ip").val();
    var interfaceName =$.trim($("#interfaceName").val());
    var interfaceMethod =$.trim($("#interfaceMethod").val());
    $.ajax({
        url:url,
        method:"get",
        data:{
            ip:ip,
            interfaceName:interfaceName,
            interfaceMethod:interfaceMethod
        },
        success:function (responseMessage) {
            if(responseMessage.success){
                var param =responseMessage.data;
                if(""!=param &&   'undefined' !=typeof (param)) {
                    var json = JSON.stringify(param)
                    $("#param").val(json)
                }
            }else {
                Ewin.alert(responseMessage.msg);
            }
        }
    })
}

// 执行调用
function invoke() {
    var url ="/dubbo/invoke";
    var ip =$("#ip").val();
    var interfaceName =$.trim($("#interfaceName").val());
    var interfaceMethod =$.trim($("#interfaceMethod").val());
    var encoding=$("#encoding").val();
    var timeout =$("#timeout").val();
    var param =JSON.stringify(paramEditor.get());
    $.ajax({
        url:url,
        method:"get",
        data:{
            host:ip,
            interfaceName:interfaceName,
            interfaceMethod:interfaceMethod,
            encoding:encoding,
            timeout:timeout,
            param:param
        },
        success:function (responseMessage) {
            //转成javascript对象
            var o =JSON.parse(responseMessage);
            resultEditor.set(o);
        }
    })
}
function invokeForTestCase() {
    var interfaceId =$("#interfaceId").val();
    var param =JSON.stringify(paramEditor.get());
    var url ="/dubbo/invokeForTestCase";
    $.ajax({
        url:url,
        method:"post",
        data:{
            param:param,
            id:interfaceId
        },success:function (result) {
            var o =JSON.parse(result);
            resultEditor.set(o);
        }
    })
};
function invokeForTestPlan(interfaceId,param) {
    var url ="/dubbo/invokeForTestPlan";
    $.ajax({
        url:url, method:"post", data:{
            param:param,
            interfaceId:interfaceId
        },success:function (responseMessage) {
            try {
                var o = $.parseJSON(responseMessage);
                resultJsonEditor.set(o);
            }catch (e) {
                resultJsonEditor.set(responseMessage);
            }
        }
    })
}
